package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.manager.SharedPreferenceManager;
import com.tianhui.consignortwofei.mvp.model.enty.ConsignorInfo;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2021/1/21
 * @description
 **/
public class ConsignorListAdapter extends RecyclerArrayAdapter<ConsignorInfo> {

    public ConsignorListAdapter(Context context) {
        super(context);
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ConsignorListViewHolder(parent, R.layout.item_consignor_list);
    }

    private class ConsignorListViewHolder extends BaseViewHolder<ConsignorInfo> {

        private TextView consignorTextView;
        private ImageView checkImageView;
        private TextView tv_counts;

        public ConsignorListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            consignorTextView = getView(R.id.item_consignor_list_consignorTextView);
            checkImageView = getView(R.id.item_consignor_list_checkImageView);
            tv_counts = getView(R.id.tv_counts);
        }

        @Override
        public void setData(ConsignorInfo data) {
            super.setData(data);
            consignorTextView.setText(data.customername);
            String consignorId = SharedPreferenceManager.getInstance().getConsignorId();
            if (!TextUtils.isEmpty(consignorId) && consignorId.equals(data.useId)) {
                checkImageView.setVisibility(View.VISIBLE);
            } else {
                checkImageView.setVisibility(View.GONE);
            }

            tv_counts.setText("("+data.counts+")");

        }
    }
}
